// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import $ from 'jquery'//jquery引入
import 'bootstrap/js/bootstrap.min.js'
import 'bootstrap/css/bootstrap.min.css'
import './assets/bootstrap/js/jquery-3.2.1.min.js'
import './assets/layui/layui.all.js'
import './assets/layui/css/layui.css'
import './assets/font-awesome-4.7.0/css/font-awesome.min.css'
//elementui
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'

Vue.use(ElementUI)


Vue.config.productionTip = false
Vue.prototype.router = router;/*将router绑定到全局  防止点击页面老是刷新页面*/
var axios = require('axios')
axios.defaults.baseURL = 'http://localhost:10000'/*http://localhost:10000/bk-employee*/
// 将API方法绑定到全局
Vue.prototype.$axios = axios
Vue.config.productionTip = false
 
// router.beforeEach((to, from, next) => {
//   alert(to);
// })
router.beforeEach((to, from, next) => {
  /* 判断该路由是否需要登录权限 */
  if (to.meta.requiresAuth) {
      if(window.localStorage['Authorization']==undefined){
        return next({path:'/'});
      }else{
        next();
      }
  }
  next();
})

/* eslint-disable */
new Vue({
  el: '#app',
  router,
  components: { App },
  template: '<App/>'
})



//自动给同一个vue项目的所有请求添加请求头
axios.interceptors.request.use(function (config) {
	let token = window.localStorage['Authorization'];//localStorage.getItem('Authorization');
	if (token) {
		//config.headers['Authorization'] = token;
		config.headers.common = {
	      'Authorization': token
	    }
	}
	return config;
})

